﻿
package extremefx.collections {
	import extremefx.IEnumerable;	
	import extremefx.IEnumerator;	
	
	/**
	 * @author Marcelo Volmaro
	 */
	public final class GenericEnumerator {

		public static function getEnumerator(pObj:*):IEnumerator {
			
			if (pObj is Object){
				if (pObj is IEnumerable)
					return IEnumerable(pObj).getEnumerator();
				
				if (pObj is Array)
					return new NativeArrayEnum(pObj as Array);
					
				//don't know any better way :(...
				if (!(pObj is Class)){
					var a:Array = [], i:uint = 0;
					for each(var v:Object in pObj){
						a[i++] = v;
					}
					
					return new NativeArrayEnum(a);
				}
			}
			
			return null;
		}

	}
}